#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
#include<stdlib.h>
#include <sys/types.h>
int main()
{
  pid_t ids[10];
  for(int i=0;i<10;i++)
  {
    pid_t id = fork();
    if(id == 0)
    {
      int count=1;
      while(count>0) {
        printf("child do something!: %d,%d\n",getpid(),getppid());
        sleep(1);
        count--;
      }
      exit(i);
    }
    ids[i] = id;

  }

  int  count=0;
  while(count<10)
  {
    int status = 0;
    pid_t ret=waitpid(ids[count],&status,0);
    if(ret>=0)
    {
      printf("wait child success! %d\n",ret);
      printf("status:%d\n",status);
      printf("child get signal:%d\n", status&0x7f);
      if(WIFEXITED(status)){  //只有进程是正确的运行完毕了，退出码才有意义

      printf("child exit code %d\n",WEXITSTATUS(status));
      }
      else{
        printf("child not exit normal!\n");
      }
    //  printf("child get signal:%d\n", status&0x7f);
    //  printf("child exit code %d\n",(status>>8)&0xff);
    }
    count++;
  }

 
  return 0;
}
